import java.util.ArrayList;

public class ClassTest {
    /*1:定义一个ClassRoom类,包含构造方法,提供get/set方法
        班级名称,className(String 类型)	班级类型:classType(String 类型)
        班级人数:classCount(int 类型)
    2.定义测试类ClassTest,完成以下要求：
        定义方法，public static ArrayList<ClassRoom> getClassCount (ArrayList<ClassRoom> list)，获得班
        级人数大于50人，并且班级类型是Java的，添加到新的集合中返回。
        在main方法中完成以下功能：创建2个ClassRoom对象并赋值，
        并且将ClassRoom对象添加到ArrayList<ClassRoom>集合中，
        调用getClassCount方法并接收，遍历返回的新集合输出新集合中所有元素信息*/
    public static void main(String[] args) {
        ClassRoom cls1 = new ClassRoom("10班", "Java", 50);
        ClassRoom cls2 = new ClassRoom("11班", "Java", 55);
        ClassRoom cls3 = new ClassRoom("12班", "Python", 50);
        ClassRoom cls4 = new ClassRoom("13班", "Java", 40);
        ClassRoom cls5 = new ClassRoom("14班", "Java", 56);
        ArrayList<ClassRoom> oldList = new ArrayList<>();
        oldList.add(cls1);
        oldList.add(cls2);
        oldList.add(cls3);
        oldList.add(cls4);
        oldList.add(cls5);
        ArrayList<ClassRoom> finalList = getClassCount(oldList);
//        遍历这个集合
        for (int i = 0; i < finalList.size(); i++) {
            ClassRoom cr = finalList.get(i);
            System.out.println(cr.getClassCount()+"..."+cr.getClassName()+"..."+cr.getClassType());
        }
    }

    public static ArrayList<ClassRoom> getClassCount(ArrayList<ClassRoom> list) {
        ArrayList<ClassRoom> newList = new ArrayList<>();
//            遍历旧集合,将旧集合中的满足条件的对象放入新集合中
        for (int i = 0; i < list.size(); i++) {
            ClassRoom cr = list.get(i);
//            判断对象中的条件是否满足,满足的话输出到新集合中
            if ("Java".equals(cr.getClassType()) && cr.getClassCount() >= 50) {
                newList.add(cr);
            }
        }
        return newList;
    }
}

class ClassRoom {
    private String className;
    private String classType;
    private int classCount;

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public String getClassType() {
        return classType;
    }

    public void setClassType(String classType) {
        this.classType = classType;
    }

    public int getClassCount() {
        return classCount;
    }

    public void setClassCount(int classCount) {
        this.classCount = classCount;
    }

    public ClassRoom(String className, String classType, int classCount) {

        this.className = className;
        this.classType = classType;
        this.classCount = classCount;
    }

    public ClassRoom() {

    }
}



